<template>
    <div class="addEditArticlePageCont">
      <div class='title'>当前位置：问答审核 / 审核问答内容</div>
      <div class="addEditArticlePageMian">
        <Form ref="formAddEditArticle" :label-width="110">
          <FormItem label="问答分类：">
            {{QAclassification}}
            <span v-if="buildingAlias"> - </span>
            {{buildingAlias}}
          </FormItem>
          <FormItem label="问题描述：" prop="articleTitle">
            {{problemDescription}}
          </FormItem>
          <FormItem label="答案：" prop="articleTags">
            {{answer}}
          </FormItem>
          <div class="footer" v-if="$route.query.type != 'View'">
            <Button type="primary" @click="addEditArticleSubmit">通过审核</Button>
            <Button @click="addEditArticleReset">驳回</Button>
          </div>
        </Form>
      </div>
      <Modal
        v-model="reasonRejectionState"
        title="驳回理由"
        @on-cancel="reasonRejectionCancel" width="500" :mask-closable="false" :footerHide="true">
        <Form ref="reasonRejectionRef" :model="reasonRejectionForm" :rules="reasonRejectionRules" :label-width="100">
          <FormItem label="驳回理由：" prop="reasonRejectionVal">
            <Input type="textarea" :maxlength="100" :rows="3" v-model="reasonRejectionForm.reasonRejectionVal" placeholder="请输入驳回理由" style=" width: 100%;"></Input>
          </FormItem>
          <div class="footer">
            <Button @click="reasonRejectionCancel">取消</Button>
            <Button type="info" @click="reasonRejectionOk">确认</Button>
          </div>
        </Form>
      </Modal>
    </div>
</template>
<script>
  import { faqsGetDetails, faqsRebut } from "@/api/materialManagement.js";
  export default {
    components: {

    },
    data() {
      return {
        questionTypeList: ['产品使用', '政策行情', '法务知识', '楼盘问答', '其它'],
        QAclassification: '',
        problemDescription: '',
        answer: '',
        buildingAlias: '',
        reasonRejectionState: false,
        reasonRejectionForm: {
          reasonRejectionVal: ''
        },
        reasonRejectionRules: {
          reasonRejectionVal: [
            { required: true, message: '请输入驳回理由', trigger: 'blur' },
            { max: 100, message: '不超过100个字符', trigger: 'blur' },
          ]
        }
      }
    },
    methods: {
      // 通过审核
      addEditArticleSubmit() {
        faqsRebut({questionAnswerId: this.$route.query.questionAnswerId, auditStatus: 1}).then(res=>{
          this.$store.commit('deleteroutefun', '审核问答内容'+Math.random());
          this.$Message.success('审核问答内容成功!');
          this.$router.go(-1);
        }).catch(err=>{
          this.$Message.error(err)
        })
      },
      // 驳回
      addEditArticleReset() {
        this.reasonRejectionState = true
      },
      // 驳回理由
      reasonRejectionOk() {
        this.$refs.reasonRejectionRef.validate((valid) => {
          if (valid) {
            faqsRebut({questionAnswerId: this.$route.query.questionAnswerId, auditStatus: 2, rebutReason: this.reasonRejectionForm.reasonRejectionVal}).then(res=>{
              this.$Message.success('审核问答内容驳回成功!');
              this.reasonRejectionState = false;
              this.$router.go(-1);
            }).catch(err=>{
              this.$Message.error(err)
            })
          }
        })
      },
      reasonRejectionCancel(){
        this.reasonRejectionState = false
        this.$refs.reasonRejectionRef.resetFields();
      },
      // 初始化获取数据
      initData() {
        faqsGetDetails({questionAnswerId: this.$route.query.questionAnswerId}).then(res=>{
          if(res) {
            this.QAclassification = this.questionTypeList[res.questionType]
            this.problemDescription = res.questionDesc
            this.answer = res.answerDesc
            this.buildingAlias = res.buildingAlias
          }
        }).catch(err=>{
          this.$Message.error(err)
        })
      }
    },
    computed: {

    },
    created() {
      // 初始化获取数据
      this.initData()
    },
    activated() {

    },
    deactivated() {

    },
    mounted() {

    },
    watch: {
      // "$route"(to, from) {
      //   if(to.path == "######") {
      //     this.initData();
      //   }
      // }
    },
  }
</script>
<style lang="scss" scoped>
  .addEditArticlePageCont{
    .title{
        background-color: #f5f5f5;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
        padding: 0 14px 10px;
    }
    .addEditArticlePageMian{
      margin-top: 16px;
      width: 800px;
    }
  }
  .footer{
    padding-top: 16px;
    text-align: center;
    button{
      width: 90px;
      margin: 0 10px;
    }
  }
</style>
